package com.wmyg.antifake.gs1.ns2.converters;

import com.wmyg.antifake.gs1.ns2.ProductData;
import com.wmyg.antifake.gs1.ns2.SpecialString;
import org.dom4j.Element;

import java.util.List;

/**
 * @program: antifake
 * @description: 商品数据转换器
 * @author: wong
 * @create: 19-4-23
 */
public class ProductDataConverter {

    protected static ProductData converter(Element productDataElement) {
        ProductData productData = new ProductData();
        List<Element> children = productDataElement.elements();
        for (Element element :
                children) {
            switch (element.getName()) {
                case "gtin":
                    productData.setGtin(element.getText());
                    break;
                case "targetMarket":
                    productData.setTargetMarket(new SpecialString(element));
                    break;
                case "informationProviderGLN":
                    productData.setInformationProviderGLN(element.getText());
                    break;
                case "informationProviderName":
                    productData.setInformationProviderName(element.getText());
                    break;
                case "productDataRecord":
                    productData.setProductDataRecord(ProductDataRecordConverter.converter(element));
                    break;
                default:
            }
        }
        return productData;
    }

}
